package vcp.client.GUI.mvc.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;

import javax.swing.JComponent;
import javax.swing.JPanel;

import org.joda.time.DateTime;

import vcp.client.interfaces.IMessage;
import vcp.client.interfaces.delegates.IControllerViewDelegate;
import vcp.enums.PopUpMessageType;

/**
 * <p>
 * user interface view abstract class
 * </p>
 * 
 * @author VCP team
 * 
 */
public abstract class UIAbstractView extends JPanel implements ActionListener, IMessage
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected IControllerViewDelegate controllerDelegate;

	/**
	 * setter
	 * 
	 * @param controllerDelegate
	 */
	public void setControllerDelegate ( IControllerViewDelegate controllerDelegate )
	{
		this.controllerDelegate = controllerDelegate;
	}

	protected ArrayList <JComponent> additionalComponents;

	/**
	 * getter
	 * 
	 * @return additional components
	 */
	protected ArrayList <JComponent> getAdditionalComponents ()
	{
		if ( this.additionalComponents == null )
		{
			this.additionalComponents = new ArrayList <>();
		}
		return this.additionalComponents;
	}

	protected boolean onScreen;

	/**
	 * setter
	 * 
	 * @param onScreen
	 */
	public void setOnScreen ( boolean onScreen )
	{
		this.onScreen = onScreen;
	}

	/**
	 * getter
	 * 
	 * @return true if on screen
	 */
	public boolean isOnScreen ()
	{
		return this.onScreen;
	}

	// ****************************************************************************************************************************
	// Public methods
	// ****************************************************************************************************************************
	/**
	 * getter
	 * 
	 * @return list of additional components
	 */
	public ArrayList <JComponent> getAdditionalToolbarComponents ()
	{
		return this.getAdditionalComponents();
	}

	/**
	 * method updates view on screen
	 */
	public void updateView ()
	{
	}

	/**
	 * method clears view from screen
	 */
	public void clearView ()
	{

	}

	/**
	 * method resets view
	 */
	public void resetView ()
	{

	}

	// ****************************************************************************************************************************
	// Protected methods
	// ****************************************************************************************************************************
	/**
	 * constructor
	 */
	protected UIAbstractView ()
	{
		super();

		this.onScreen = false;
		this.setupLayout();
		this.setupListeners();
		this.setupButtonsIcons();

		this.addMouseListener(new MouseListener()
			{

				@Override
				public void mouseReleased ( MouseEvent e )
				{
				}

				@Override
				public void mousePressed ( MouseEvent e )
				{
					UIAbstractView.this.requestFocusInWindow();
				}

				@Override
				public void mouseExited ( MouseEvent e )
				{
				}

				@Override
				public void mouseEntered ( MouseEvent e )
				{
				}

				@Override
				public void mouseClicked ( MouseEvent e )
				{
				}
			});
	}

	/**
	 * method sets up screen layout
	 */
	protected abstract void setupLayout ();

	/**
	 * method sets up listeners
	 */
	protected abstract void setupListeners ();

	/**
	 * method sets up icons on buttons
	 */
	protected void setupButtonsIcons ()
	{

	}

	// ****************************************************************************************************************************
	// IMessage methods
	// ****************************************************************************************************************************
	@Override
	public DateTime requestCurrentClientDateTime ()
	{
		DateTime time = null;
		if ( this.controllerDelegate != null )
		{
			time = this.controllerDelegate.requestCurrentClientDateTime();
		}
		else
		{
			time = new DateTime();
		}
		return time;
	}

	@Override
	public void showPopUpMessage ( String displayMessage, PopUpMessageType messageType )
	{
	}

	// ****************************************************************************************************************************
	// ActionListener methods
	// ****************************************************************************************************************************

	@Override
	public void actionPerformed ( ActionEvent actionEvent )
	{
	}

}
